/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * xml_nihongo
 * Copyright (C) Massimiliano Maniscalco 2011, 2012 <massi.neptune@yahoo.com>
 * 
 * xml_nihongo is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * xml_nihongo is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "lezione.h"


void Lezione::
parse_string ( const Glib::ustring &str, list<Glib::ustring> &listStr )
{
	size_t _inizio = 0;
	size_t _fine = str.length();
	while ( _inizio < _fine )
	{
		size_t _pos = str.find_first_of ( " ,　、", _inizio );
		if ( _pos != Glib::ustring::npos )
		{
			Glib::ustring trovato = str.substr( _inizio, _pos - _inizio );				
			if ( trovato != "" )
				listStr.push_back ( trovato );
			_inizio = _pos + 1;
		}
		else
		{
			Glib::ustring trovato = str.substr( _inizio );
			if ( trovato != "" )
				listStr.push_back ( trovato );
			_inizio = _fine;
		}
	}
}

void Lezione::
create_string ( const list<Glib::ustring> &listStr, Glib::ustring &str ) const
{
	if ( listStr.size() > 0 )
	{
		list<Glib::ustring>::const_iterator _iter = listStr.begin ();
		list<Glib::ustring>::const_iterator _end = listStr.end ();
		str = *_iter;
		_iter++;
		while ( _iter != _end )
		{
			str += ", " + *_iter;
			_iter++;
		}
	}
}